package com.esri.core.internal.tasks.e.b;

import com.esri.core.ogc.wmts.WMTSLayerInfo;
import com.esri.core.ogc.wmts.WMTSServiceInfo;
import com.esri.core.ogc.wmts.WMTSTileMatrixSet;
import org.xml.sax.Attributes;

/* loaded from: classes.dex */
public class a extends com.esri.core.internal.tasks.e.a {
    public static final String c = "http://www.opengis.net/wmts/1.0";
    public static final String d = "http://www.opengis.net/ows/1.1";
    public static final String e = "http://www.w3.org/1999/xlink";
    private static final String g = "ServiceIdentification";
    private static final String h = "Value";
    private static final String i = "ServiceTypeVersion";
    private static final String j = "Title";
    private static final String k = "Abstract";
    private static final String l = "Operation";
    private static final String m = "TileMatrixSet";
    private static final String n = "Layer";
    private static final long serialVersionUID = 1;
    private boolean r;
    private String s;
    private WMTSServiceInfo o = null;
    protected StringBuilder f = null;
    private WMTSLayerInfo p = null;
    private WMTSTileMatrixSet q = null;

    public WMTSServiceInfo a() {
        return this.o;
    }

    @Override // com.esri.core.internal.tasks.e.a, org.xml.sax.helpers.DefaultHandler, org.xml.sax.ContentHandler
    public void startElement(String str, String str2, String str3, Attributes attributes) {
        super.startElement(str, str2, str3, attributes);
        this.f = new StringBuilder();
        if (a(str)) {
            String peek = this.b.peek();
            if (this.p != null && !n.equals(str2)) {
                this.p.startElement(peek, attributes);
            } else if (this.q != null && !m.equals(str2)) {
                this.q.startElement(peek, attributes);
            } else if (n.equals(peek)) {
                this.p = new WMTSLayerInfo(this.o);
            } else if (m.equals(peek)) {
                this.q = new WMTSTileMatrixSet();
            } else if (l.equals(peek)) {
                String value = attributes.getValue("name");
                if (value != null && "GetTile".equals(value)) {
                    this.r = true;
                } else {
                    this.r = false;
                }
            } else if ("Get".equals(peek) && this.r) {
                this.s = attributes.getValue("href");
            }
        }
    }

    @Override // com.esri.core.internal.tasks.e.a, org.xml.sax.helpers.DefaultHandler, org.xml.sax.ContentHandler
    public void endElement(String str, String str2, String str3) {
        if (a(str)) {
            String peek = this.b.peek();
            if (this.p != null && !n.equals(peek)) {
                this.p.endElement(peek);
            } else if (this.q != null && !m.equals(peek)) {
                this.q.endElement(peek);
            } else if (n.equals(peek)) {
                this.o.addLayer(this.p.getIdentifier(), this.p);
                this.p = null;
            } else if (m.equals(peek)) {
                this.o.addTileMatrixSet(this.q.getIdentifier(), this.q);
                this.q = null;
            } else if (k.equals(peek)) {
                c(this.f.toString());
            } else if (j.equals(peek)) {
                b(this.f.toString());
            } else if (i.equals(peek)) {
                d(this.f.toString());
            } else if (h.equals(peek) && this.r && this.s != null && this.f.toString().equals("KVP")) {
                this.o.setKVPTileRequestURL(this.s);
            }
            this.f = null;
            super.endElement(str, str2, str3);
        }
    }

    @Override // org.xml.sax.helpers.DefaultHandler, org.xml.sax.ContentHandler
    public void startDocument() {
        this.o = new WMTSServiceInfo();
    }

    @Override // com.esri.core.internal.tasks.e.a, org.xml.sax.helpers.DefaultHandler, org.xml.sax.ContentHandler
    public void characters(char[] cArr, int i2, int i3) {
        StringBuilder sb;
        super.characters(cArr, i2, i3);
        String trim = new String(cArr, i2, i3).trim();
        if (!this.b.isEmpty() && (sb = this.f) != null) {
            sb.append(trim);
        }
        WMTSLayerInfo wMTSLayerInfo = this.p;
        if (wMTSLayerInfo != null) {
            wMTSLayerInfo.characters(cArr, i2, i3);
            return;
        }
        WMTSTileMatrixSet wMTSTileMatrixSet = this.q;
        if (wMTSTileMatrixSet != null) {
            wMTSTileMatrixSet.characters(cArr, i2, i3);
        }
    }

    private boolean a(String str) {
        return c.equals(str) || d.equals(str) || "".equals(str) || "http://www.w3.org/1999/xlink".equals(str);
    }

    private void b(String str) {
        if (str == null || str.length() <= 0 || !this.b.contains(g)) {
            return;
        }
        this.o.setTitle(str);
    }

    private void c(String str) {
        if (str == null || str.length() <= 0 || !this.b.contains(g)) {
            return;
        }
        this.o.setAbstract(str);
    }

    private void d(String str) {
        if (str == null || str.length() <= 0 || !this.b.contains(g)) {
            return;
        }
        this.o.setVersion(str);
    }
}
